// pages/defect/craft/params/index.js
 

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    form: {
      maxNumber: '',
      minNumber: '',
      name: '参数'
    } 
 
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onCancel() {
      this.triggerEvent('cancel');
    },
    onSubmit(event) {
      if (this.data.form['name']  && this.data.form['maxNumber'] && this.data.form['minNumber']) {
        this.triggerEvent('submit', {
          ...event.detail.value 
        });
        return
      }
      wx.showToast({
        title: '未填写完表单',
        icon: 'none'
      })
    },
    initData(data) {
      this.setData({
        form: data
      })
 
    },
    setDefaultValue(form) {
      this.setData({
        form
      })
    },
    onSelect(event) {
      this.setData({
        form: {
          ...this.data.form 
        }
      })
    },
    setParamsType(data) {
      // this.setData({
      //   paramsType: data
      // })
      this.onClear()
    },
    onInput(event) {
      const value = event.detail,
        key = event.currentTarget.dataset.key;
      const form = this.data.form;
      form[key] = value;
      this.setData({
        form
      })
    },
    onClear() {
      this.setData({
        form: {
          maxNumber: '',
          minNumber: '',
          name: ''
        }
      })
    }
  }
})